package com.iyundao.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iyundao.io.Service.ActivityCategoryService;
import com.iyundao.io.model.ActivityCategory;
import com.iyundao.io.tools.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/activitycategory")
public class ActivityCategoryController {

    @Autowired
    private ActivityCategoryService activityCategoryService;

    @ApiOperation(value="添加活动类型", notes="添加活动类型")
    @RequestMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData insert(@RequestBody JSONObject params) {
        ActivityCategory activityCategory = JSON.toJavaObject(params, ActivityCategory.class);
        return activityCategoryService.insert(activityCategory);
    }

    @ApiOperation(value="查询所有活动类型", notes="查询所有活动类型")
    @RequestMapping(value = "/findall", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public List<ActivityCategory> findAll(){
        return activityCategoryService.findAll();
    }
}
